<?php

$act = isset($_GET["act"]) ? $_GET["act"] : '';

switch ($act){
    case "q":
        include_once "page/questions.php";
        break;
    case "aq":
        if(is_post($_SERVER["REQUEST_METHOD"])){
            # 接收数据
            $name = $_POST["name"];
            $maxnum = $_POST["maxnum"];
            $type = $_POST["type"];
            $operator = $_POST["operator"];
            $times = $_POST["times"];
            # 计算生成题库
            switch ($type){
                # 运算
                case 1:
                    break;
                # 混合运算
                case 2:
                    break;
                # 比大小
                case 3:
                    break;
                # 等式比大小
                case 4:
                    break;
                default:
                    break;
            }

            # 构造存储数据
            # 存储
            echo "<pre>";
            print_r($_POST);
            echo "</pre>";
            die;
        }
        include_once "page/questions_add.php";
        break;
    case "t":
        include_once "page/tests.php";
        break;
    default:
        include_once "page/index.php";
        break;
}
function is_post($type){
    return $type == "POST" ? true : false;
}
class questions
{
    public $maxnum;
    public $operator;
    public $times;

    # 接收参数
    public function set($arg)
    {
        $this->maxnum = $arg["maxnum"];
        $this->operator = $this->getOperator($arg["operator"]);
        $this->times = $arg["times"];
        return $this;
    }

    public function create()
    {
        # 生成试题
        for($i=0;$i<$this->maxnum;$i++){
            if ($this->times > 1){

            }
        }
        # 数据统计
        # 创建文件
        # 返回数据
    }

    private function getOperator($params)
    {
        $data = [];
        foreach ($params as $v){
            $arr = [];
            switch ($v){
                case "plus":
                    $arr = [
                        "name" => $v,
                        "value" => "＋",
                        "action" => "+",
                    ];
                    break;
                case "less":
                    $arr = [
                        "name" => $v,
                        "value" => "－",
                        "action" => "-",
                    ];
                    break;
                case "multiply":
                    $arr = [
                        "name" => $v,
                        "value" => "×",
                        "action" => "*",
                    ];
                    break;
                case "except":
                    $arr = [
                        "name" => $v,
                        "value" => "÷",
                        "action" => "/",
                    ];
                    break;
            }
            array_push($data,$arr);
        }
        return $data;
    }

}
?>